package com.project.class3_30;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadMore {

    public static void main(String[] args) {
        //创建无限扩展线程池，每添加一个任务会创建新线程
//        ExecutorService es = Executors.newCachedThreadPool();

        //创建固定大小的线程池。如果任务数量超过空闲线程数量，多余任务等待
//        ExecutorService es = Executors.newFixedThreadPool(2);

        //创建单线程线程池。如果有多个任务，顺序执行
        ExecutorService es = Executors.newSingleThreadExecutor();
        //添加任务，任务类必须实现Runnable接口
        es.execute(new One());
        es.execute(new Two());
        es.execute(new Three());
        //关闭线程池
        es.shutdown();
    }
}

class One implements Runnable{

    @Override
    public void run() {
        for(int i=0;i<10;i++){
            System.out.print("*");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Two implements Runnable{

    @Override
    public void run() {
        for(int i=0;i<10;i++){
            System.out.print("#");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Three implements Runnable{

    @Override
    public void run() {
        for(int i=0;i<10;i++){
            System.out.print("$");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}